package com.projectName.www.servlet;

import com.projectName.www.po.User;
import com.projectName.www.service.UserService;
import com.projectName.www.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/userListServlet")
public class UserListServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        String method=request.getParameter("method");
//        if(method!=null&&method.equals("query")){
//
//        }
        UserService service=new UserServiceImpl();

        List<User>users=service.findall();
        //第二步可以将list存入request狱中

        System.out.println(users);
        request.setAttribute("users",users);
        //第三步转发到list.jsp
        request.getRequestDispatcher("/userlist.jsp").forward(request,response);
    }
//    private void query()


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
